<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h3> 在数组中找出最大值最小值</h3>

    <script>
        function find(arr) {
            let min = arr[0]
            let max = arr[0]
            let i;
            for (i = 0; i < arr.length; i++) {
                if (arr[i] < min) {
                    min = arr[i]
                } else if (arr[i] > max) {
                    max = arr[i]
                }
            }
            console.log('最大值：' + max);
            console.log('最小值：' + min);

        }

        //let arr = [-2, -1, 5, 2, 10, 8, 4, 50, -100];
        let arr = [10, -5, -5, -6]
        find(arr);
    </script>

</body>

</html>